package com.exonline.back.controller.info;
/**
 * @desc 数据分析模块C层
 * @author hbrj
 */
import com.exonline.commons.entity.OnlineInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/admin/info")
public class InfoServlet extends HttpServlet {

    ObjectMapper mapper = new ObjectMapper();//初始化ObjectMapper,目的是为了向前台传递json格式数据
    InfoService service = new InfoService();//引入数据分析模块m层

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        if(method!=null){
           if(method.equals("onlineinfo")){
               getOnlineInfo(req, resp);
           }
        }
    }
    /**
     * @desc 1.获取服务器数据分析的相关数据
     * @author hbrj
     */
    private  void getOnlineInfo(HttpServletRequest req, HttpServletResponse resp) throws IOException {

        try {
            OnlineInfo onlineInfo = service.getOnlineInfo(req);
            mapper.writeValue(resp.getWriter(), onlineInfo);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
